package com.key.win.business.chat.eums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.key.win.base.enumjson.TextureEnumSerializerCode;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@JsonSerialize(using = TextureEnumSerializerCode.class)
public enum ImMessageContentTypeEnum {
    NORMAL(0, "常规消息"),
    TEXT(1, "文本消息"),
    IMAGE(2, "图片消息"),
    AUDIO(3, "音频消息"),
    VIDEO(4, "视频消息"),
    APPLICATION(5, "应用数据");
    @EnumValue
    private int code;
    private String text;

    private ImMessageContentTypeEnum(int code, String text) {
        this.code = code;
        this.text = text;
    }


    public int getCode() {
        return code;
    }

    public String getText() {
        return text;
    }

    public static ImMessageContentTypeEnum getImMessageContentTypeEnumByName(String name) {
        if (StringUtils.isNotBlank(name)) {
            for (ImMessageContentTypeEnum imcte : ImMessageContentTypeEnum.values()) {
                if (name.toLowerCase().contains(imcte.name().toLowerCase())) {
                    return imcte;
                }
            }
        }
        return null;
    }

    public static ImMessageContentTypeEnum getImMessageContentTypeEnum(String name) {
        ImMessageContentTypeEnum imMessageContentTypeEnumByName = getImMessageContentTypeEnumByName(name);
        if (imMessageContentTypeEnumByName != null) {
            return imMessageContentTypeEnumByName;
        }
        return ImMessageContentTypeEnum.NORMAL;
    }

    public static List<ImMessageContentTypeEnum> getImMessageContentTypeEnums(String names){
        String[] messageContentTypes = names.split(",");
        List<ImMessageContentTypeEnum> collection = new ArrayList<>();
        for (String messageContentType : messageContentTypes) {
            ImMessageContentTypeEnum imMessageContentTypeEnum = getImMessageContentTypeEnumByName(messageContentType);
            if (imMessageContentTypeEnum != null) {
                collection.add(imMessageContentTypeEnum);
            }
        }
        return collection;
    }
}
